package com.espirit.eap.util;

import java.math.BigDecimal;

public class BigDecimalUtil {
	
	public static BigDecimal getValue(BigDecimal value){
		return value == null ? BigDecimal.ZERO : value;
	}
	
	public static BigDecimal getBigDecimalValue(Object value){
		if (value == null) return null;
		if (value instanceof Double 
				|| value instanceof Integer
				|| value instanceof BigDecimal
				|| value instanceof Float
				|| value instanceof Long
				|| value instanceof Number){
			return new BigDecimal(value.toString());
		}
		return null;
	}
	
	public static BigDecimal substract(BigDecimal one, BigDecimal two){
		one = getValue(one);
		two = getValue(two);
		return one.subtract(two);
	}
	
	public static BigDecimal add(BigDecimal one, BigDecimal two){
		one = getValue(one);
		two = getValue(two);
		return one.add(two);
	}
}
